File Scanner: A Demo

by Gordon Sweet Gordon@gsweet.fsnet.co.uk


Home

Tip Corner

API Corner

Just for fun

Timing Events

QCard Lesson

Menus: Checkmarks

Dissolve Demo

Encryption

Poker Game

Snip Manager

Demos

Newsletter help

Index

File Scanner

For those of a curious nature like me, here is a simple little program that can be used to safely scan any file to read any ASCII text within. It can even be used on some of the more obscure files on the Windows Directory.

At the start you will notice how both txtX, the buttons, and initial text have been set to try to match the display being used; likewise the maximum characters to be shown are set with maxX and maxY. The filedialog defaults to the Root Directory, and once a file is selected, you are prompted to decide if you want Line Breaks ( Chr$(13) ) to be recognized. This is useful to see TXT and BAS files etc in their true format, but which can take up considerable screen space otherwise. In order to maintain the exact format of LB code, the characters \ and | have been replaced by /. Unreadable text is filtered out by rejecting ASCII codes under 32 or greater than 126.

Gordon Sweet -- Gordon@gsweet.fsnet.co.uk


    ' Simple file scanner with CHR$ \ and | replaced by /
    nomainwin
    txtX = DisplayWidth/2 - 300
    button #s, "Next Page ", [go2], LL DisplayWidth-100, 80
    button #s, "Abort View", [fin2], LL DisplayWidth-100, 40
    open "Scan" for graphics_fs_nsb as #s
    #s "trapclose [quit]; font arial 18 bold; color blue; place ";txtX;" ";200
    #s "\This will safely scan any file and display all the"
    #s "\readable bytes. Click on NEXT PAGE to start."
    maxX = 96/800*DisplayWidth
    maxY = DisplayHeight -80
    scn = 0 : File$ = ""
    playwave "chimes.wav"
    wait

[which]
    DefaultDir$ = left$(DefaultDir$,2)+"\" ' START AT ROOT DIRECTORY
    #s "cls; font fixedsys; color red; place 20 12"
    #s "\**** WAIT FOR COMPLETION OF SCANNING ****"
    #s "flush; color black"
    text$="\" : newline = 0
    filedialog "ANY FILE!","*.*",File$
    if File$ = "" then [nofile]
    confirm "Accept Line Breaks?"; nl$
    if nl$ = "yes" then newline = 1
[file]
    #s "cls; color black; place 20 12"
    scn = 1
    open File$ for input as #scn
[read2]
    scan
    if eof(#scn) <> 0 then [fin2]
    dat$ = input$(#scn, 1)
    chr = asc(dat$)
    ' avoid / line break with LB code
    if dat$ = "\" or dat$ = "|" then dat$ = "/"
    if newline = 0 then [miss]
    if chr = 10 then     ' new line
        #s text$
        text$ = "\"
    end if
[miss]   ' Accept only CHR$ 32  to 126
    if chr > 31 and chr < 127 then text$ = text$ + dat$ 
    if len(text$) > maxX then ' width of Display
        print#s, text$ 
        text$ = "\" ' ready for new line
    end if
[next]
    #s "posxy x y"
    if y > maxY then gosub [halt2] ' height of Display
    goto [read2]

[fin2]
    if File$ = "" then [quit]
    close #scn : scn = 0
    #s text$
    confirm "SCAN COMPLETED - Another File ?"; q$
    if q$ = "yes" then [which] else [quit]

[halt2]
    playwave "XXX.wav" ' instead of BEEP
    wait ' next page ?

[go2]
    if File$ = "" then [which]
    #s "cls; color black; place 20 12"
    return

[nofile]
    confirm "No File Selected! Abort?"; q$
    if q$ = "no" then [which]

[quit]
    if scn = 1 then close #scn
    close #s : end